#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.config.filter;

import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version: 1.00.00
 * @description: 过滤器配置
 * @copyright: Copyright (c) 2021 知羽软件 All Rights Reserved
 * @company: 厦门知羽软件有限公司
 * @author: hj
 * @date: 2021-06-10 16:46
 */
@Configuration
public class FilterConfig {
    @Value("${symbol_dollar}{xss.enabled}")
    private String enabled;

    @Value("${symbol_dollar}{xss.excludes}")
    private String excludes;

    @Value("${symbol_dollar}{xss.urlPatterns}")
    private String urlPatterns;
    @Value("${symbol_pound}{'${symbol_dollar}{log.excludeUrlList}'.split(',')}")
    private List<String> excludeUrlList;

//    @Bean
//    public FilterRegistrationBean xssFilterRegistration() {
//        FilterRegistrationBean registration = new FilterRegistrationBean();
//        registration.setDispatcherTypes(DispatcherType.REQUEST);
//        registration.setFilter(new XssFilter());
//        //添加过滤路径
//        registration.addUrlPatterns(StrUtil.split(urlPatterns, ",").stream().toArray(String[]::new));
//        registration.setName("xssFilter");
//        //设置初始化参数
//        Map<String, String> initParameters = new HashMap<String, String>();
//        initParameters.put("excludes", excludes);
//        initParameters.put("enabled", enabled);
//        registration.setInitParameters(initParameters);
//        registration.setOrder(2);
//        return registration;
//    }
//    @Bean(name = "logFilter")
//    public FilterRegistrationBean logFilter() {
//        FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
//        filterRegistration.setFilter(new LogPrintFilter(excludeUrlList));
//        filterRegistration.addUrlPatterns("/*");
//        return filterRegistration;
//    }
}
